
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        2/7/2009
 * PROJECT:             MCWEBSITE
 * PURPOSE:             websiteCustomerEmailDAL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Web.Configuration;
using System.Collections.Generic;
using System.Data;
using MCWEBSITE.ENTITY;


namespace MCWEBSITE.DAL
{
    public class websiteCustomerEmailDAL
    {
        #region  Properties
		 
		public static string FIELD_CUSTOMEREMAILID = "CustomerEmailId";  
		public static string FIELD_CUSTOMERNAME = "CustomerName";  
		public static string FIELD_CUSTOMEREMAIL = "CustomerEmail";  
		public static string FIELD_CUSTOMERPHONE = "CustomerPhone";  
		public static string FIELD_CUSTOMERJOB = "CustomerJob";  
		public static string FIELD_CUSTOMERADDRESS = "CustomerAddress";  
		public static string FIELD_DESCRIPTION = "Description"; 
		public static string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ContentConnectionString"].ToString();

        #endregion

        #region Protected methods

        /// <summary>
        /// Select entity of websiteCustomerEmail
        /// </summary>
        /// <param name="CustomerEmailId">Primary Keys</param>
        /// <returns>Collection of websiteCustomerEmailInfo</returns>
        public static websiteCustomerEmailInfo SelectOne(int CustomerEmailId)
        {
            websiteCustomerEmailInfo _websiteCustomerEmailInfo = new websiteCustomerEmailInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteCustomerEmailSelectOne", CustomerEmailId);
                if (dr.Read())
                    setwebsiteCustomerEmailInfo(dr, ref _websiteCustomerEmailInfo);
                return _websiteCustomerEmailInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select all websiteCustomerEmail
        /// </summary>
        /// <returns>Collection of websiteCustomerEmailInfo</returns>
        public static List<websiteCustomerEmailInfo> SelectAll()
        {
            List<websiteCustomerEmailInfo> lstwebsiteCustomerEmail = new List<websiteCustomerEmailInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteCustomerEmailSelectAll");
                setListwebsiteCustomerEmailInfo(ref dr, ref lstwebsiteCustomerEmail);
                return lstwebsiteCustomerEmail;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select
        /// </summary>
        /// <param name="websiteCustomerEmailnfo">Modify this method adapting your need</param>
        /// <returns>Collection of websiteCustomerEmailInfo</returns>
        public static List<websiteCustomerEmailInfo> SelectFilters()
        {
            string criterias = string.Empty;
            List<websiteCustomerEmailInfo> lstwebsiteCustomerEmail = new List<websiteCustomerEmailInfo>();
            SqlDataReader dr = null;
            try 
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteCustomerEmailSelectByFilters");
                setListwebsiteCustomerEmailInfo(ref dr, ref lstwebsiteCustomerEmail);
                return lstwebsiteCustomerEmail;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Insert websiteCustomerEmail
        /// </summary>
        /// <param name="websiteCustomerEmailInfo">Entity of websiteCustomerEmail</param>
        /// <returns>error code</returns>
        public static int Insert(websiteCustomerEmailInfo _websiteCustomerEmailInfo)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteCustomerEmailInsert" 
											, _websiteCustomerEmailInfo.CustomerName
											, _websiteCustomerEmailInfo.CustomerEmail
											, _websiteCustomerEmailInfo.CustomerPhone
											, _websiteCustomerEmailInfo.CustomerJob
											, _websiteCustomerEmailInfo.CustomerAddress
											, _websiteCustomerEmailInfo.Description
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        
        /// <summary>
        /// Update websiteCustomerEmail
        /// </summary>
        /// <param name="websiteCustomerEmailInfo">Entity of websiteCustomerEmail</param>
        /// <returns>error code</returns>
        public static int Update(websiteCustomerEmailInfo _websiteCustomerEmailInfo)
        {            
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteCustomerEmailUpdate"
											, _websiteCustomerEmailInfo.CustomerEmailId
											, _websiteCustomerEmailInfo.CustomerName
											, _websiteCustomerEmailInfo.CustomerEmail
											, _websiteCustomerEmailInfo.CustomerPhone
											, _websiteCustomerEmailInfo.CustomerJob
											, _websiteCustomerEmailInfo.CustomerAddress
											, _websiteCustomerEmailInfo.Description
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Delete SchoolAdmin
        /// </summary>
        /// <param name="CustomerEmailId">Primary Key</param>
        /// <returns>error code</returns>
        public static int Delete(int CustomerEmailId)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteCustomerEmailDelete", CustomerEmailId);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        public static DataSet CustomerEmailFilter(string CusID, string CusName, string CusEmail)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = SqlHelper.ExecuteDataset(ConnectionString, "sp_mc_websiteCustomerEmailGetWithFilter", "'" + CusID + "'", "N'%" + CusName + "%'", "N'%" + CusEmail + "%'");
                return ds;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region "Utilities method"
		
        private static void setListwebsiteCustomerEmailInfo(ref SqlDataReader dr, ref List<websiteCustomerEmailInfo> lstwebsiteCustomerEmail)
        {
            websiteCustomerEmailInfo _websiteCustomerEmailInfo = null;
            while (dr.Read())
            {
                _websiteCustomerEmailInfo = new websiteCustomerEmailInfo();
                setwebsiteCustomerEmailInfo(dr, ref _websiteCustomerEmailInfo);
                lstwebsiteCustomerEmail.Add(_websiteCustomerEmailInfo);
            }
        }

        private static void setwebsiteCustomerEmailInfo(SqlDataReader dr, ref websiteCustomerEmailInfo _websiteCustomerEmailInfo)
        {
			_websiteCustomerEmailInfo.CustomerEmailId = dr[websiteCustomerEmailDAL.FIELD_CUSTOMEREMAILID] != DBNull.Value ? Convert.ToInt32(dr[websiteCustomerEmailDAL.FIELD_CUSTOMEREMAILID]) : 0;
			_websiteCustomerEmailInfo.CustomerName = dr[websiteCustomerEmailDAL.FIELD_CUSTOMERNAME] != DBNull.Value ? Convert.ToString(dr[websiteCustomerEmailDAL.FIELD_CUSTOMERNAME]) : string.Empty;
			_websiteCustomerEmailInfo.CustomerEmail = dr[websiteCustomerEmailDAL.FIELD_CUSTOMEREMAIL] != DBNull.Value ? Convert.ToString(dr[websiteCustomerEmailDAL.FIELD_CUSTOMEREMAIL]) : string.Empty;
			_websiteCustomerEmailInfo.CustomerPhone = dr[websiteCustomerEmailDAL.FIELD_CUSTOMERPHONE] != DBNull.Value ? Convert.ToString(dr[websiteCustomerEmailDAL.FIELD_CUSTOMERPHONE]) : string.Empty;
			_websiteCustomerEmailInfo.CustomerJob = dr[websiteCustomerEmailDAL.FIELD_CUSTOMERJOB] != DBNull.Value ? Convert.ToString(dr[websiteCustomerEmailDAL.FIELD_CUSTOMERJOB]) : string.Empty;
			_websiteCustomerEmailInfo.CustomerAddress = dr[websiteCustomerEmailDAL.FIELD_CUSTOMERADDRESS] != DBNull.Value ? Convert.ToString(dr[websiteCustomerEmailDAL.FIELD_CUSTOMERADDRESS]) : string.Empty;
			_websiteCustomerEmailInfo.Description = dr[websiteCustomerEmailDAL.FIELD_DESCRIPTION] != DBNull.Value ? Convert.ToString(dr[websiteCustomerEmailDAL.FIELD_DESCRIPTION]) : string.Empty;
			                        
        }
        #endregion Methods

        #region Private Members

        private static string TABLE_NAME = "[mc_websiteCustomerEmail]";

        #endregion
    }
}

		